package shiyong3rd.springBeanUtil;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * @Auther lujieni
 * @Date 2020/6/30
 * Spring实现的BeanUtils.copyProperties是浅拷贝
 * 参数名一致类型不一致不能拷贝!!!
 * int age -> Integer age ok
 * int age -> String  age ng
 * null -> null 资源对象的属性null也会拷贝到目标对象中去,要注意!!!
 */
public class UseBeanUtil {

    public static void main(String[] args) {
   /*     Student s = new Student();
        s.setAge(28);
        StudentDTO s2 = new StudentDTO();
        BeanUtils.copyProperties(s,s2);
        System.out.println(s2);*/

        A a = new A();
        Student student = new Student();
        student.setAge(30);
        student.setNum(181268);
        a.setS1(student);
        a.setName("lujieni");
        B b = new B();
        BeanUtils.copyProperties(a,b);
        System.out.println(JSONObject.toJSONString(b));
    }

}

@Data
class Student{
    private int age;
    private Integer num;
}

@Data
class StudentDTO{
    private Integer age;
    private Integer num;
}

@Data
class A extends Father{
    private Student s1;
}

@Data
class B extends Father{
    private Student s1;
}

@Data
class Father{
    private String name;
}




